#include "widget.h"
#include "ui_widget.h"
#include<QPainter>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *event)
{
    (void) event;
    //绘图工作放到这里进行
    QPainter painter(this);

//    QFont font("宋体", 24);
//    painter.setFont(font);

//    QPen pen;
//    pen.setColor(QColor(255, 0, 0));
//    pen.setWidth(5);
//    pen.setStyle(Qt::DashLine);
//    painter.setPen(pen);

//    QBrush brush;
//    brush.setColor(QColor(0, 255, 0));
//    //brush.setStyle(Qt::SolidPattern);//实线填充
//    // 其他风格填充
//    //brush.setStyle(Qt::Dense1Pattern);
//    brush.setStyle(Qt::CrossPattern);
//    painter.setBrush(brush);
//    //画一个线段
//    painter.drawLine(20, 20, 300, 40);
//    painter.drawLine(QPoint(10,10), QPoint(300,30));
//    //画一个矩形
//    painter.drawRect(100,100,300,400);
//    //画圆形
//    painter.drawEllipse(200,200,100,100);
//    //绘制文本
//    painter.drawText(0,100,"nihao?");

    QPixmap pixmap(":/cat.jpg");

    //painter.drawPixmap(0,0,pixmap);
    //图片缩放
    //painter.drawPixmap(100,100,400,300,pixmap);
    //图片旋转 本质上是吧QPainter对象进行旋转，绘制出来的内容也就进行了旋转
    painter.rotate(180);
    painter.translate(-800,-600);

    painter.drawPixmap(100,100,400,300,pixmap);

}

